import {
  request,
  BASEURL
} from '../../utils/request';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsMnie: {},
    money: '',
    kahao: '',
    name: '',
    title: '',
    title1: ''
  },


  onLoad: function (options) {

  },
  //form表单
  async submitForm(e) {
    let {
      openid
    } = wx.getStorageSync('uid')
    let {
      jine,
      kahao,
      name,
      title,
      title1
    } = e.detail.value
    //验证信息
    if (jine == '' || kahao == '' || name == '' || title == '' || title1 == '') {
      wx.showToast({
        title: '必要信息不能为空',
        icon: 'none'
      })
    } else if (jine < 1) {
      wx.showToast({
        title: '金额不能小于1',
        icon:'none'
      })

    } else {
      let res = await request({
        url: '/api/Wxapp/applyWithdrawal',
        method: 'POST',
        data: {
          openid,
          amount: jine,
          user_name: name,
          bank_name: title,
          bank_card: kahao,
          bank_addr: title1
        },
      })
      console.log(res)
      if (res.data.code == 1) {
        this.userInfo()
        this.setData({
          money: '',
          kahao: '',
          name: '',
          title: '',
          title1: ''
        })
        wx.showToast({
          title: '操作成功'
        })
        setTimeout(()=>{
          wx.switchTab({
            url: '/pages/index/index',
          })
        },2000)
      }else if(res.data.code==0){
        wx.showToast({
          title: res.data.msg,
          icon:"none"
        })
      }
    }

  },





  //获取余额
  async userInfo() {
    let {
      openid
    } = wx.getStorageSync('uid')
    let res = await request({
      url: '/api/Wxapp/userInfo',
      method: "POST",
      data: {
        openid
      }
    })
    console.log(res)
    let goodsMnie = res.data.data
    this.setData({
      goodsMnie,
      BASEURL
    })
  },
  // 全部提现
  change() {
    let money = this.data.goodsMnie.profit
    this.setData({
      money
    })
  },
  onShow: function () {
    this.userInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let {openid} = wx.getStorageSync('uid')
    return {
      title: "邀请好友",
      path:`/pages/index/index?pid=${openid}` 
    }
  }
})